import request from "@/utils/request"
/* 
    三级分类列表的内容
*/

//1,获取一级商品列表
//一级商品列表返回值每一项类型
export interface reqCategory1ListItemType {
    id: number ;
    name: string ;
    category1Id?: number ;
    category2Id?: number ;
}

//一级商品列表返回值类型
export type reqCategory1ListReturnType = reqCategory1ListItemType[]

export const requestCategory1List = () => {
    return request.get<any,reqCategory1ListReturnType>("/admin/product/getCategory1")
}

//2,获取二级商品列表
export const requestCategory2List = (category1Id: number) => {
    return request.get<any,reqCategory1ListReturnType>(`/admin/product/getCategory2/${category1Id}`)
}

//3,获取三级商品列表
export const requestCategory3List = (category2Id: number) => {
    return request.get<any,reqCategory1ListReturnType>(`admin/product/getCategory3/${category2Id}`)
}

/* 
    以下是attr的内容
*/

//类型
//属性值的类型
export interface attrValueItemType {
    id?: number;
    valueName: string;
    attrId: number | undefined;
    isEdit?: boolean
  }

//属性类型 
export interface attrType {
        id?: number;
        attrName: string;
        categoryId: number;
        categoryLevel: number;
        attrValueList: attrValueItemType[]
    }

//属性列表的属性
export type attrListType = attrType[]

//4,获取三级分类的属性
export const requestAttrList = (
    category1Id:number,
    category2Id: number,
    category3Id: number
) => {
   return request.get<any,attrListType>(
    `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`
   ) 
}

//5删除某个属性
export const requestDeleteAttr = (attrId: number) => {
    return request.delete<any, null>(`/admin/product/deleteAttr/${attrId}`)
}

//新增或修改某个属性
export const requestUpdateOrAddAttr = (newAttr:attrListType) => {
    return request.post<any, null>(`/admin/product/saveAttrInfo`, newAttr)
}

/* 
{
  "attrName": "string",
  "attrValueList": [
    {
      "attrId": 0,
      "id": 0,
      "valueName": "string"
    }
  ],
  "categoryId": 0,
  "categoryLevel": 0,
  "id": 0
}

*/


